﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BySoft.Server.Common.Schema;
using BySoft.Server.Common.Entity;
using BySoft.Web.Utility;
using BySoft.Server.Business;
using BySoft.Server.Consts;
using BySoft.Server.Common;
using BySoft.Server.Common.Enum;
using OneSoft.EntityCore;

namespace BySoft.Web.Site.SysManage
{
    public partial class RoleEdit :  AuthBasePage
    {
        string m_RoleId = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            m_RoleId = HttpUtility.UrlDecode(UIHelper.GetQueryStringValue("ROLE_ID"));
            if (!IsPostBack)
            {

                SysRoleExEntity oSysRole = SysRole.GetSysRoleExEntity(m_RoleId);
                if (oSysRole != null)
                {
                    lblName.Text = oSysRole.RoleName;
                    txtDesc.Text = oSysRole.Description;
                    hfCreateUser.Value = oSysRole.CreateUserID;
                    lblCreator.Text = oSysRole.Createusername;
                    lblCreateTime.Text = oSysRole.CreateDate.Value.ToString("yyyy-MM-dd");
                    lblModifyUser.Text = oSysRole.Modifyusername;
                    lblModifyDate.Text = oSysRole.ModifyDate.Value.ToString("yyyy-MM-dd");


                    BindRights();
                    DtMember = SysRole.GetRoleMember(m_RoleId);
                    DtMember.Columns.Add("TempType");
                    for (int i = 0; i < DtMember.Rows.Count; i++)
                    {
                        DtMember.Rows[i]["TempType"] = "1";
                    }
                    BindMember();

                    if (m_RoleId == CommonConsts.Admin_Role_ID)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "", "<script>CheckAll1()</script>");
                    }
                }
            }

        }

        private void BindRights()
        {
            DtRoleRights = SysRolerights.GetDSByCondition(" where " + SysRolerightsTable.C_ROLEID + "='" + m_RoleId + "'").Tables[0];
            DtModuleRights = SysModule.GetSysModuleList();
            if (DtModuleRights.Rows.Count > 0)
            {
                sgvRights.DataSource = DtModuleRights;
                sgvRights.DataBind();
            }
            else
            {
                DataTable dtTemp = DtModuleRights.Clone();
                UIHelper.BindEmptyGridView(sgvRights, dtTemp);
            }
        }

        private void BindMember()
        {

            if (DtMember.Rows.Count > 0)
            {
                DataTable dtMember = DtMember.Clone();
                for (int i = 0; i < DtMember.Rows.Count; i++)
                {
                    if (DtMember.Rows[i]["TempType"].ToString() != "0")
                    {
                        dtMember.ImportRow(DtMember.Rows[i]);
                    }
                }

                sgvMember.DataSource = dtMember;
                sgvMember.DataBind();
            }
            else
            {
                UIHelper.BindEmptyGridView(sgvMember, DtMember);
            }
        }

        protected DataTable DtMember
        {
            get
            {
                if (Session["RoleEdit_DtMember"] != null)
                {
                    return (DataTable)Session["RoleEdit_DtMember"];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                Session["RoleEdit_DtMember"] = value;
            }
        }




        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            SysRoleEntity oSysRole = new SysRoleEntity();
            oSysRole.RoleID = int.Parse(m_RoleId);
            oSysRole.RoleName = lblName.Text;
            oSysRole.Description = txtDesc.Text.Trim();
            oSysRole.Status = "1";
            oSysRole.CreateUserID = hfCreateUser.Value;
            oSysRole.CreateDate = DateTime.Parse(lblCreateTime.Text);
            oSysRole.ModifyUserID = CurrentUser.UserID;
            oSysRole.ModifyDate = DateTime.Now;

            List<SysRolerightsEntity> listSysRolerights = new List<SysRolerightsEntity>();
            List<SysUserroleEntity> listSysUserrole = new List<SysUserroleEntity>();
            List<SysUserroleEntity> listSysUserroleDel = new List<SysUserroleEntity>();


            //角色权限
            foreach (GridViewRow gvr in sgvRights.Rows)
            {
                if (sgvRights.DataKeys[gvr.RowIndex].Values[SysModuleTable.C_PAGETYPE].ToString().Equals("S") || sgvRights.DataKeys[gvr.RowIndex].Values[SysModuleTable.C_MODULEID].ToString().Equals("QC01CustomsQueryRep"))
                {
                    string sTemp = "";
                    if (((CheckBox)gvr.FindControl("cbView")).Checked && ((CheckBox)gvr.FindControl("cbView")).Visible)
                    {
                        sTemp = "R";
                    }
                    if (!sTemp.Equals(""))
                    {
                        SysRolerightsEntity oSysRolerights = new SysRolerightsEntity();
                        oSysRolerights.RoleID = oSysRole.RoleID;
                        oSysRolerights.RightsCode = sTemp;
                        oSysRolerights.ModulePrimaryID = Convert.ToInt32(sgvRights.DataKeys[gvr.RowIndex].Values["ModulePrimaryID"].ToString());
                        //oSysRolerights.Datarights = "";
                        listSysRolerights.Add(oSysRolerights);
                    }
                }
                if (!sgvRights.DataKeys[gvr.RowIndex].Values[SysModuleTable.C_PAGETYPE].ToString().Equals("T")&&
                    !sgvRights.DataKeys[gvr.RowIndex].Values[SysModuleTable.C_PAGETYPE].ToString().Equals("S"))
                {
                    string sTemp = "";
                    if (((CheckBox)gvr.FindControl("cbView")).Checked && ((CheckBox)gvr.FindControl("cbView")).Visible)
                    {
                        sTemp = "R";
                    }
                    if (((CheckBox)gvr.FindControl("cbAdd")).Checked && ((CheckBox)gvr.FindControl("cbAdd")).Visible)
                    {
                        sTemp += "C";
                    }
                    if (((CheckBox)gvr.FindControl("cbDel")).Checked && ((CheckBox)gvr.FindControl("cbDel")).Visible)
                    {
                        sTemp += "D";
                    }
                    if (((CheckBox)gvr.FindControl("cbUpdate")).Checked && ((CheckBox)gvr.FindControl("cbUpdate")).Visible)
                    {
                        sTemp += "U";
                    }
                    if (((CheckBox)gvr.FindControl("cbExport")).Checked && ((CheckBox)gvr.FindControl("cbExport")).Visible)
                    {
                        sTemp += "E";
                    }
                    if (((CheckBox)gvr.FindControl("cbApprove")).Checked && ((CheckBox)gvr.FindControl("cbApprove")).Visible)
                    {
                        sTemp += "A";
                    }
                    
                    if (!sTemp.Equals(""))
                    {
                        SysRolerightsEntity oSysRolerights = new SysRolerightsEntity();
                        oSysRolerights.RoleID = oSysRole.RoleID;
                        oSysRolerights.RightsCode = sTemp;
                        oSysRolerights.ModulePrimaryID = Convert.ToInt32(sgvRights.DataKeys[gvr.RowIndex].Values["MODULEPRIMARYID"].ToString());
                        //oSysRolerights.Datarights = "";
                        listSysRolerights.Add(oSysRolerights);
                    }
                }
            }
            if (DtMember == null)
            {
                return;
            }
            for (int i = 0; i < DtMember.Rows.Count; i++)
            {

                if (DtMember.Rows[i]["TempType"].ToString() == "2")
                {
                    SysUserroleEntity oSysUserrole = new SysUserroleEntity();
                    oSysUserrole.UserID = DtMember.Rows[i]["ID"].ToString();
                    oSysUserrole.RoleID = oSysRole.RoleID;
                    listSysUserrole.Add(oSysUserrole);
                }
                if (DtMember.Rows[i]["TempType"].ToString() == "0")
                {
                    SysUserroleEntity oSysUserrole = new SysUserroleEntity();
                    oSysUserrole.UserRoleID = int.Parse(DtMember.Rows[i]["UserRoleID"].ToString());
                    oSysUserrole.RoleID = oSysRole.RoleID;
                    listSysUserroleDel.Add(oSysUserrole);
                }
            }
            if (SysRole.UpdateRole(oSysRole, listSysRolerights, listSysUserrole, listSysUserroleDel))
            {
                DtMember = null;
                WriteLog(oSysRole, listSysRolerights, listSysUserrole, true);
                UIHelper.AlertMessageGoToURL(this.Page, Message.SaveSuccess, "/SysManage/RoleList.aspx");
            }
            else
            {
                WriteLog(oSysRole, listSysRolerights, listSysUserrole, false);
                UIHelper.AlertMessage(this.Page, Message.SaveFail);
            }
        }

        private void WriteLog(SysRoleEntity oSysRole, List<SysRolerightsEntity> listSysRolerights, List<SysUserroleEntity> listSysUserrole, bool isResult)
        {
            DataTable dt1 = CommonMethod.convert2Table(listSysRolerights);
            DataTable dt2 = CommonMethod.convert2Table(listSysUserrole);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt1);
            ds.Tables.Add(dt2);

            oSysRole.SubDataSet = ds;

            base.LogAction(BaseEnum.ActionType.Modify, oSysRole.RoleID.Value.ToString(), isResult, null, new EntityBase[] { oSysRole });

        }

        protected void sgvRights_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Header)
            {

                bool isView = true, isAdd = true, isDel = true, isUpdate = true, isExport = true ,isApp = true; 
                if (DtRoleRights.Rows.Count < DtModuleRights.Select(SysModuleTable.C_PAGETYPE + "='F'").Length)
                {
                    isView = false;
                    isAdd = false;
                    isDel = false;
                    isUpdate = false;
                    isExport = false;
                }
                for (int i = 0; i < DtRoleRights.Rows.Count; i++)
                {
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("R"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("R"))
                            {
                                isView = false;
                            }
                        }
                    }
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("C"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("C"))
                            {
                                isAdd = false;
                            }
                        }
                    }
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("D"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("D"))
                            {
                                isDel = false;
                            }
                        }
                    }
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("U"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("U"))
                            {
                                isUpdate = false;
                            }
                        }
                    }
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("E"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("E"))
                            {
                                isExport = false;
                            }
                        }
                    }
                    if (!DtRoleRights.Rows[i][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("A"))
                    {
                        DataRow[] dr = DtModuleRights.Select(SysModuleTable.C_MODULEPRIMARYID + "='" + DtRoleRights.Rows[i][SysRolerightsTable.C_MODULEPRIMARYID].ToString() + "'");
                        if (dr.Length > 0)
                        {
                            if (dr[0][SysModuleTable.C_MODULERIGHTS].ToString().Contains("A"))
                            {
                                isApp = false;
                            }
                        }
                    }
                }
                ((CheckBox)e.Row.FindControl("cbViewAll")).Checked = isView;
                ((CheckBox)e.Row.FindControl("cbAddAll")).Checked = isAdd;
                ((CheckBox)e.Row.FindControl("cbDelAll")).Checked = isDel;
                ((CheckBox)e.Row.FindControl("cbUpdateAll")).Checked = isUpdate;
                ((CheckBox)e.Row.FindControl("cbExportAll")).Checked = isExport;
                ((CheckBox)e.Row.FindControl("cbAll")).Checked = (isView && isAdd && isDel && isUpdate && isExport);

            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                /*-------功能名称缩进  tina.su Add   --------------------------------------*/
                //HtmlGenericControl divName = (HtmlGenericControl)e.Row.FindControl("divName");
                //if (divName != null)
                //{
                //    int level = GetModuleLevel(sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULEID].ToString());
                //    if (level > 0)
                //    {
                //        string className = "Padding" + level.ToString();
                //        divName.Attributes["class"] = className;
                //    }   
                //}
                /*---------------------------------------------------------------------------*/
                //add by liu
                //((CheckBox)e.Row.FindControl("cbApprove")).Visible = false;
                if (sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_PAGETYPE].ToString().Equals("F"))
                {
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("R"))
                    {
                        ((CheckBox)e.Row.FindControl("cbView")).Visible = false;
                    }
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("C"))
                    {
                        ((CheckBox)e.Row.FindControl("cbAdd")).Visible = false;
                    }
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("D"))
                    {
                        ((CheckBox)e.Row.FindControl("cbDel")).Visible = false;
                    }
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("U"))
                    {
                        ((CheckBox)e.Row.FindControl("cbUpdate")).Visible = false;
                    }
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("E"))
                    {
                        ((CheckBox)e.Row.FindControl("cbExport")).Visible = false;
                    }
                    if (!sgvRights.DataKeys[e.Row.RowIndex].Values[SysModuleTable.C_MODULERIGHTS].ToString().Contains("A"))
                    {
                        ((CheckBox)e.Row.FindControl("cbApprove")).Visible = false;
                    }
                    DataRow[] dr = DtRoleRights.Select(SysRolerightsTable.C_ROLEID + "='" + m_RoleId + "' and " +
                        SysRolerightsTable.C_MODULEPRIMARYID + "=" + Convert.ToInt32(sgvRights.DataKeys[e.Row.RowIndex].Values["MODULEPRIMARYID"]));
                    if (dr.Length > 0 && !string.IsNullOrEmpty(CommonMethod.GetString(sgvRights.DataKeys[e.Row.RowIndex].Values["MODULEPRIMARYID"])))
                    {
                        bool isView = true, isAdd = true, isDel = true, isUpdate = true, isExport = true, isApp = true; ;

                        if (((CheckBox)e.Row.FindControl("cbView")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("R"))
                            {
                                ((CheckBox)e.Row.FindControl("cbView")).Checked = true;
                            }
                            else
                            {
                                isView = false;
                            }
                        }
                        if (((CheckBox)e.Row.FindControl("cbAdd")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("C"))
                            {
                                ((CheckBox)e.Row.FindControl("cbAdd")).Checked = true;
                            }
                            else
                            {
                                isAdd = false;
                            }
                        }
                        if (((CheckBox)e.Row.FindControl("cbDel")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("D"))
                            {
                                ((CheckBox)e.Row.FindControl("cbDel")).Checked = true;
                            }
                            else
                            {
                                isDel = false;
                            }
                        }
                        if (((CheckBox)e.Row.FindControl("cbUpdate")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("U"))
                            {
                                ((CheckBox)e.Row.FindControl("cbUpdate")).Checked = true;
                            }
                            else
                            {
                                isUpdate = false;
                            }
                        }
                        if (((CheckBox)e.Row.FindControl("cbExport")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("E"))
                            {
                                ((CheckBox)e.Row.FindControl("cbExport")).Checked = true;
                            }
                            else
                            {
                                isExport = false;
                            }
                        }
                        if (((CheckBox)e.Row.FindControl("cbApprove")).Visible)
                        {
                            if (dr[0][SysRolerightsTable.C_RIGHTSCODE].ToString().Contains("A"))
                            {
                                ((CheckBox)e.Row.FindControl("cbApprove")).Checked = true;
                            }
                            else
                            {
                                isApp = false;
                            }
                        }
                        ((CheckBox)e.Row.FindControl("cbRowAll")).Checked = (isView && isAdd && isDel && isUpdate && isExport);

                    }
                }
                else
                {
                    ((CheckBox)e.Row.FindControl("cbRowAll")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbView")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbAdd")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbDel")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbUpdate")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbExport")).Visible = false;
                    ((CheckBox)e.Row.FindControl("cbApprove")).Visible = false;
                }
                if (sgvRights.DataKeys[e.Row.RowIndex].Values["MODULEID"].ToString().Equals("QC01CustomsQueryRep"))
                {
                    ((CheckBox)e.Row.FindControl("cbRowAll")).Visible = true;
                    ((CheckBox)e.Row.FindControl("cbView")).Visible = true;
                    DataRow[] drs = DtRoleRights.Select(SysRolerightsTable.C_ROLEID + "='" + m_RoleId + "' and " + SysRolerightsTable.C_MODULEPRIMARYID + "='" + sgvRights.DataKeys[e.Row.RowIndex].Values["MODULEPRIMARYID"].ToString() + "'");
                    if (drs.Length > 0)
                    {
                        ((CheckBox)e.Row.FindControl("cbRowAll")).Checked = true;
                        ((CheckBox)e.Row.FindControl("cbView")).Checked = true;
                    }
                    else
                    {
                        ((CheckBox)e.Row.FindControl("cbRowAll")).Checked = false;
                        ((CheckBox)e.Row.FindControl("cbView")).Checked = false;
                    }
                }
            }
        }

        protected DataTable DtRoleRights
        {
            get
            {
                if (Session["RoleAdd_DtRoleRights"] != null)
                {
                    return (DataTable)Session["RoleAdd_DtRoleRights"];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                Session["RoleAdd_DtRoleRights"] = value;
            }
        }

        protected DataTable DtModuleRights
        {
            get
            {
                if (Session["RoleAdd_DtModuleRights"] != null)
                {
                    return (DataTable)Session["RoleAdd_DtModuleRights"];
                }
                else
                {
                    return null;
                }
            }
            set
            {
                Session["RoleAdd_DtModuleRights"] = value;
            }
        }

        protected void sgvMember_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "del")
            {
                for (int i = 0; i < DtMember.Rows.Count; i++)
                {
                    if (DtMember.Rows[i]["ID"].ToString() == e.CommandArgument.ToString())
                    {
                        if (DtMember.Rows[i]["TempType"].ToString() == "1")
                        {
                            DtMember.Rows[i]["TempType"] = "0";
                        }
                        else
                        {
                            DtMember.Rows.RemoveAt(i);
                            DtMember.AcceptChanges();
                        }
                        break;
                    }
                }
                BindMember();
                //ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "<script>showtab(2)</script>", false);
            }
        }

        protected void sgvMember_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                ImageButton ibtn = (ImageButton)e.Row.FindControl("ibtnDel");
                Button btnDel = (Button)e.Row.FindControl("btnDel");
                if (ibtn != null)
                {
                    ibtn.OnClientClick = "ShowTopConfirm('提示信息','您正在删除成员：" + e.Row.Cells[1].Text + "，您确认继续吗？','confirmCallback(\\'" + btnDel.ClientID + "\\')');return false;";
                }
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (Session["RoleMember_Member"] != null)
            {
                if (DtMember.Rows[0][0].ToString().Equals(""))
                {
                    DtMember.Rows.RemoveAt(0);
                    DtMember.AcceptChanges();
                }

                DataTable dtNew = (DataTable)Session["RoleMember_Member"];
                for (int i = 0; i < dtNew.Rows.Count; i++)
                {
                    DataRow[] drs = DtMember.Select("ID='" + dtNew.Rows[i]["ID"].ToString() + "'");
                    if (drs.Length == 0)
                    {
                        for (int j = 0; j < dtNew.Columns.Count; j++)
                        {
                            if (dtNew.Rows[i][j].ToString().Equals("&nbsp;"))
                            {
                                dtNew.Rows[i][j] = "";
                            }
                        }
                        DtMember.ImportRow(dtNew.Rows[i]);
                    }
                    else
                    {
                        if (drs[0]["TempType"].ToString() == "0")
                        {
                            drs[0]["TempType"] = "1";
                        }
                    }
                }
                DtMember.AcceptChanges();
                BindMember();
                Session["RoleMember_Member"] = null;
            }
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "", "<script>iframeAutoFit();</script>", false);
        }

        public string GetModuleName(object moduleName)
        {
            if (!moduleName.ToString().StartsWith(" "))//一级菜单粗体
            {
                moduleName = "<B>" + moduleName + "</B>";
            }
            return moduleName.ToString().Replace(" ", "&nbsp;");

        }



        /// <summary>
        ///  获取菜单级别
        /// </summary>
        /// <param name="ModuleID">菜单ID</param>
        /// <returns></returns>
        /// <remarks >Autor:Tina.su</remarks>
        private int GetModuleLevel(string moduleID)
        {
            int count = 1;
            DataRow[] rows = DtModuleRights.Select(SysModuleTable.C_MODULEID + "='" + moduleID + "'");
            if (rows.Length > 0)
            {
                if (!rows[0][SysModuleTable.C_PAGETYPE].ToString().Equals("T"))//非一级菜单
                {
                    count += GetModuleLevel(rows[0][SysModuleTable.C_PARENTMODULEID].ToString());//加上上级菜单级别
                }
                return count;
            }
            else
                return -1;//模块不存在，返回-1

        }
    }
}
